// pages/index/listQuery/list/list.js
const util = require("../../../../utils/util");
const app = getApp();
let toggleCollection = true;
Page({
  data: {
    nameList: [],
    scroll: false,
    cityName:''
  },
  onLoad: function (options) {
    // util.colleation(this, "名单查询");
    toggleCollection = true;
    util.getUrl(app.globalData.url).then(res => {
      let $getResult = {
        ac: 'type',
        citycode: options.citycode,
      };
      util.bstrequest('listQuery.php', $getResult, 'POST').then(res => {
        let nameList = JSON.parse(JSON.stringify(res.data.type));
        nameList.forEach((item, index) => {
          if (item.name == options.list_name)
            item.isClick = true;
          else
            item.isClick = false;
        });
        this.setData({
          nameList,
          cityName:options.cityName
        });
      });
    });

  },
  bindList: function (e) {
    let modelId = e.currentTarget.dataset.id;
    let listName = e.currentTarget.dataset.name;
    if (modelId==1) {
      ks.navigateTo({
        url:`/pages/tools/yaohaojieguo/yaohaojieguo?city=${this.data.cityName}`,
      })
      return;
    }
    this.data.nameList.forEach((item, index) => {
      if (item.id == modelId)
        item.isClick = true;
      else
        item.isClick = false;
    });
    this.setData({
      nameList: this.data.nameList
    });
    ks.redirectTo({
      url: `/pages/tools/listQuery/index/index?modelId=${modelId}&citycode=${this.data.citycode}&cityName=${this.data.cityName}`,
    })
  },
  onPageScroll() {
    if (toggleCollection) {
      this.setData({
        scroll: true,
      });
      toggleCollection = false;
    }

  },
  closeCollection() {
    toggleCollection = false;
  },
  openCollection() {
    toggleCollection = true;
  }
})